<template>
    <el-drawer v-model="visible" :show-close="false">
        <template #header="{ close, titleId, titleClass }">
            <h4 :id="titleId" :class="titleClass">角色编辑</h4>
            <el-button type="danger" @click="close">
                <el-icon class="el-icon--left">
                    <CircleCloseFilled />
                </el-icon>
                关闭
            </el-button>
        </template>
        <el-form ref="formRef" :model="row" label-width="100px" class="demo-ruleForm">
            <el-form-item label="名称" prop="name">
                <el-input v-model.number="row.name" type="text" autocomplete="off" />
            </el-form-item>

            <el-form-item label="keyName" prop="username">
                <el-input v-model.number="row.username" type="text" autocomplete="off" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm(formRef)">Submit</el-button>
                <el-button @click="resetForm(formRef)">Reset</el-button>
            </el-form-item>
        </el-form>
    </el-drawer>
</template>
  
<script lang="ts" setup>
import { ref, defineExpose, defineProps, reactive } from "vue";
import { ElButton, ElDrawer } from "element-plus";
import type { FormInstance } from "element-plus";
import { CircleCloseFilled } from "@element-plus/icons-vue";
import { IUserList } from "@/types";

defineProps({
    row: {},
});
let visible = ref(false);
let formRef = ref<FormInstance>();

const submitForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return;
    formEl.validate((valid) => {
        if (valid) {
            console.log("submit!");
        } else {
            console.log("error submit!");
            return false;
        }
    });
};

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return;
    formEl.resetFields();
};
//暴露
defineExpose({
    visible,
});
</script>
  